package com.xxchat.entity.po;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Date;
import com.xxchat.entity.enums.DateTimePatternEnum;
import com.xxchat.utils.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;


/**
 * 用户信息表
 * @author Waicc
 */
@Setter
@Accessors(chain = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserInfo implements Serializable {


	/**
	 * 用户ID
	 */
	private String userId;

	/**
	 * 邮箱
	 */
	private String email;

	/**
	 * 昵称
	 */
	private String nickName;

	/**
	 * 加好友设置 0:不需要同意 1:需要同意
	 */
	private Integer joinType;

	/**
	 * 性别 0:女 1:男
	 */
	private Integer sex;

	/**
	 * 密码
	 */
	private String password;

	/**
	 * 个性签名
	 */
	private String introduction;

	/**
	 * 状态 0:禁用 1:可用
	 */
	private Integer status;

	/**
	 * 创建时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;

	/**
	 * 当前登录时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date currentLoginTime;

	/**
	 * 当前登录ip
	 */
	private String currentLoginIp;

	/**
	 * 当前登录地区
	 */
	private String currentLoginArea;

	/**
	 * 当前登录地区编号
	 */
	private String currentLoginAreaCode;

	/**
	 * 上次登录时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date lastLoginTime;

	/**
	 * 上次登录ip
	 */
	private String lastLoginIp;

	/**
	 * 上次登录地区
	 */
	private String lastLoginArea;

	/**
	 * 上次登录地区编号
	 */
	private String lastLoginAreaCode;

	/**
	 * 最后下线时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date lastOffTime;

	/**
	 * 是否删除 0:否 1:是
	 */
	private Integer isDelete;

	private Integer onLineType;

	public Integer getOnLineType() {
		if (null != this.currentLoginTime && null != this.lastOffTime && this.currentLoginTime.after(this.lastOffTime)) {
			return 1;
		}
		if (null != this.lastLoginTime && this.lastLoginTime.after(this.lastOffTime)) {
			return 1;
		}
		return 0;
	}

	@Override
	public String toString (){
		return "用户ID:"+(userId == null ? "空" : userId)+"，邮箱:"+(email == null ? "空" : email)+"，昵称:"+(nickName == null ? "空" : nickName)+"，加好友设置 0:不需要同意 1:需要同意:"+(joinType == null ? "空" : joinType)+"，性别 0:女 1:男:"+(sex == null ? "空" : sex)+"，密码:"+(password == null ? "空" : password)+"，个性签名:"+(introduction == null ? "空" : introduction)+"，状态 0:禁用 1:可用:"+(status == null ? "空" : status)+"，创建时间:"+(createTime == null ? "空" : DateUtil.format(createTime, DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern()))+"，当前登录时间:"+(currentLoginTime == null ? "空" : DateUtil.format(currentLoginTime, DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern()))+"，当前登录ip:"+(currentLoginIp == null ? "空" : currentLoginIp)+"，当前登录地区:"+(currentLoginArea == null ? "空" : currentLoginArea)+"，当前登录地区编号:"+(currentLoginAreaCode == null ? "空" : currentLoginAreaCode)+"，上次登录时间:"+(lastLoginTime == null ? "空" : DateUtil.format(lastLoginTime, DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern()))+"，上次登录ip:"+(lastLoginIp == null ? "空" : lastLoginIp)+"，上次登录地区:"+(lastLoginArea == null ? "空" : lastLoginArea)+"，上次登录地区编号:"+(lastLoginAreaCode == null ? "空" : lastLoginAreaCode)+"，最后下线时间:"+(lastOffTime == null ? "空" : DateUtil.format(lastOffTime, DateTimePatternEnum.YYYY_MM_DD_HH_MM_SS.getPattern()))+"，是否删除 0:否 1:是:"+(isDelete == null ? "空" : isDelete);
	}

	public String getUserId() {
		return userId;
	}

	public String getEmail() {
		return email;
	}

	public String getNickName() {
		return nickName;
	}

	public Integer getJoinType() {
		return joinType;
	}

	public Integer getSex() {
		return sex;
	}

	public String getPassword() {
		return password;
	}

	public String getIntroduction() {
		return introduction;
	}

	public Integer getStatus() {
		return status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public Date getCurrentLoginTime() {
		return currentLoginTime;
	}

	public String getCurrentLoginIp() {
		return currentLoginIp;
	}

	public String getCurrentLoginArea() {
		return currentLoginArea;
	}

	public String getCurrentLoginAreaCode() {
		return currentLoginAreaCode;
	}

	public Date getLastLoginTime() {
		return lastLoginTime;
	}

	public String getLastLoginIp() {
		return lastLoginIp;
	}

	public String getLastLoginArea() {
		return lastLoginArea;
	}

	public String getLastLoginAreaCode() {
		return lastLoginAreaCode;
	}

	public Date getLastOffTime() {
		return lastOffTime;
	}

	public Integer getIsDelete() {
		return isDelete;
	}
}
